// 输入框组件实例

import { assignInWith } from 'lodash'
import type {
    dateRangeConfigType,
    inputConfigType,
    signatureConfigType,
    tableConfigType
} from '../../../../../types/index'
import BaseEntity from '../../BaseEntity'
import { uid } from 'uid'
import type { configType, slotFormConfigType } from '../../BaseEntity'
import { entityType } from '../..'
import type { TableColumnData, TableData } from '@arco-design/web-vue'
import RoleApi from '@/api/system/role/RoleApi'
import UserApi from '@/api/user/UserApi'



export default class SignatureEntity extends BaseEntity {
    constructor(config: configType, slotFormConfig: slotFormConfigType) {
        let baseConfig: configType = {
            class: ['draggable-form-hover'],
            style: { width: '100%' },
            field: 'Signature_' + uid(4),
            label: "电子签名",
            required: false,
            hideLabel: false,
            rules:[{

              validator: (value, cb) => {
                if (this.config.required&&!value.base64ImgData) {
                  cb('请先进行签名')
                } else {
                  cb()
                }
              }
            }]
        }
        let baseSlotFormConfig:slotFormConfigType = {
          modelValue:{
            dotData:[], // 将签名处理成点数据
            base64ImgData:'' // 将签名处理成base64图片数据
          } , //该自定义组件中暂未使用该字段 默认所有组件都需要定义该字段
          dotSize:  (0.5 + 2.5) / 2,
          penColor: '#165dff',
          backgroundColor: '#f2f3f5'
        }
        let componentConfig: signatureConfigType = {
          dotSize:{
            type:'inputNumber',
            formItemConfig:{
              label:'画笔大小',
            },
            formItemElement:{
               modelValue:0.5,
               placeholder:'请输入画笔大小',
            }
          },
          penColor:{
            type:'colorPicker',
            formItemConfig:{
              label:'画笔颜色',
            },
            formItemElement:{
               modelValue:'black',
              placeholder:'请输入',
            }
          },
          backgroundColor:{
            type:'colorPicker',
            formItemConfig:{
              label:'画布颜色',
            },
            formItemElement:{
               modelValue:'#f5f6f6',
              placeholder:'请输入',
            }
          } 
          
         
        }

        super(
            entityType.signature,
            assignInWith(baseConfig, config),
            assignInWith(baseSlotFormConfig, slotFormConfig),
            componentConfig
        )



        this.initSlotFormConfig()
    }
    initSlotFormConfig() {
        //初始化表单组件可配置项 因为表单组件可配置项是根据表单组件所拥有得属性来定义的 配置项得值需要对应初始化实例得对应属性得值
        Object.keys(this.componentConfig).forEach(key => {
            if (this.slotFormConfig[key]) {
                this.componentConfig[key].formItemElement.modelValue = this.slotFormConfig[key]
            }
        })
    }

}

